package com.ruoyi.system.xmlAbstract.interfaces.fileGenerate.impl;

import com.ruoyi.system.xmlAbstract.interfaces.fileGenerate.FileGenerateInterface;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author : anxinr
 * @date : 2023/1/16 18:10
 */
@Slf4j
@Component(value = "XmlFileGenerate")
public class XmlFileGenerate implements FileGenerateInterface {
    @Override
    public void generateFile(String path,String fileName ,String data) throws Exception {
        /**生成的文件*/
        File file = new File(path);
        /**不存在则创建*/
        if (!file.exists()) {
            file.mkdirs() ;
        }
        FileWriter writer;
        try {
            writer = new FileWriter(new File(path + fileName));
            /**清空原文件内容*/
            writer.write("");
            writer.write(data);
            writer.flush();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
